package maze;

import java.util.Random;

public class Maze {
    private static final int SIZE = 8;
    private int[][] maze;
    private int playerX;
    private int playerY;

    public Maze() {
        maze = new int[SIZE][SIZE];
        playerX = 0;
        playerY = 0;
        generateMaze();
        maze[playerX][playerY] = -1; 
        maze[SIZE - 1][SIZE - 1] = 2; 
    }

    private void generateMaze() {
        Random random = new Random();
        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {
                if (random.nextDouble() < 0.3) {
                    maze[i][j] = 1; 
                } else {
                    maze[i][j] = 0; 
                }
            }
        }
        maze[0][0] = 0; 
        maze[SIZE - 1][SIZE - 1] = 0; 
    }

    public void printMaze() {
        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {
                if (maze[i][j] == -1) {
                    System.out.print("P ");
                } else if (maze[i][j] == 1) {
                    System.out.print("1 ");
                } else if (maze[i][j] == 2) {
                    System.out.print("E ");
                } else {
                    System.out.print("0 ");
                }
            }
            System.out.println();
        }
    }

    public boolean canMove(int newX, int newY) {
        return newX >= 0 && newX < SIZE && newY >= 0 && newY < SIZE && maze[newX][newY] != 1;
    }

    public void movePlayer(int newX, int newY) {
        maze[playerX][playerY] = 0;
        playerX = newX;
        playerY = newY;
        maze[playerX][playerY] = -1;
    }

    public int getPlayerX() {
        return playerX;
    }

    public int getPlayerY() {
        return playerY;
    }

    public boolean isGameOver() {
        return playerX == SIZE - 1 && playerY == SIZE - 1;
    }
}    